<!-- 考勤表 -->
<template>
	<view class="p-3">
		<bg-search2 v-if="showSearch" class="mb-3" @search="searchHandler" title="选择查询项目" label="项目名称">
		</bg-search2>
		<view v-if="dataList.length>0">
			<u-list :style="{height:showSearch?'calc(100vh - 465rpx)':'calc(100vh - 140rpx)'}" @scrolltolower="loadMore()">
				<u-list-item v-for="(item, index) in dataList" :key="index" @click="gotoDetail(item)">
					<view class="bt-block mb-3">
						<bg-cell2 :border="false">
							<template slot="label">
								<view class="flex">
									<view class="font-gray mr-4"> 项目名称 </view>
									<view class="font-gray2" style="width: 370rpx;">{{item.projectName}}</view>
								</view>
							</template>
							<template slot="value">
								<view class="new-btn" @tap="gotoDetail(item)">考勤详情</view>
							</template>
						</bg-cell2>
					</view>
				</u-list-item>
			</u-list> 
		</view>
		<u-empty v-else></u-empty>
		
	</view>
</template>

<script>
	import {
		getList
	} from "@/api/attend.js"
	import {getProjectEntry}from "@/api/project.js"
	export default {
		data() {
			return {
				showSearch:false,
				dataList: [],
				total: 0,
				params: {
					projectName:'',
					pageNum: 1,
					pageSize: 20
				}
			}
		},
		onLoad(options){
			if(options.show){
				this.showSearch = true
			}
		},
		mounted() {
			this.getData()
		},
		methods: {
			searchHandler(e){
				this.params.pageNum = 1
				this.params.projectName = e
				this.dataList = []
				this.getData()
			},
			getData() {
				getProjectEntry(this.params).then(res => {
					this.dataList = [...this.dataList, ...res.data.rows]
					this.total = res.data.total
				})
			},
			loadMore() {
				if (this.dataList.length < this.total) {
					this.params.pageNum += 1
					this.getData()
				}
			},
			gotoDetail(item) {
				uni.navigateTo({
					url: "/pages/attendance/attendance/detail?pid="+item.id
				})
			}
		}
	}
</script>

<style scoped>
	.new-btn {
		width: 130rpx;
		height: 52rpx;
		line-height: 52rpx;
		background: #ffefe7;
		border-radius: 8rpx;
		font-size: 22rpx;
		font-family: PingFang SC, PingFang SC-Medium;
		font-weight: 500;
		text-align: center;
		color: #ee3636;
	}
</style>